<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class AddPriceToWaimaiDetails extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('waimai_order_details', function (Blueprint $table) {
            $table->unsignedInteger('originalPrice')->default(0)->after('originalUnitPrice')->comment('原总价');
            $table->unsignedInteger('discountPrice')->default(0)->after('payPrice')->comment('该行的优惠金额');
        });

        // 洗数据
        \App\Kuafu\WaiMai\Model\WaiMaiOrderDetailModel::query()->update(['originalPrice' => DB::raw('originalUnitPrice*num'), 'discountPrice' => DB::raw('originalUnitPrice*num-payPrice')]);
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('waimai_order_details', function (Blueprint $table) {
            $table->dropColumn('originalPrice');
            $table->dropColumn('discountPrice');
        });
    }
}
